//
//  regionListView.m
//  FastRunDemo
//
//  Created by 苟亚明 on 16/10/23.
//  Copyright © 2016年 苟亚明. All rights reserved.
//

#import "regionListView.h"
#import "schoolModel.h"
@interface regionListView() <UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;

/** 校区数据*/
@property (nonatomic, strong) NSMutableArray *arrRegion;
@end

@implementation regionListView

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.arrRegion.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *const cellID = @"regionCellId";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    
    cell.textLabel.text = self.arrRegion[indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if ([self.delegate respondsToSelector:@selector(regionListView:didSelectRowAtIndexPath:)]) {
        [self.delegate regionListView:tableView didSelectRowAtIndexPath:indexPath];
    }
    [self removeFromSuperview];
}

- (IBAction)btnClick:(id)sender {
    [self removeFromSuperview];
}

- (void)awakeFromNib{
    [super awakeFromNib];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
}

- (NSMutableArray *)arrRegion{
    if (!_arrRegion) {
        _arrRegion = [NSMutableArray array];
        
        for (int i = 0; i < self.modelArr.count; i++) {
            schoolModel *model = self.modelArr[i];
            if ([model.UNIVERSITY_NAME isEqualToString:self.schoolName]) {
                [_arrRegion addObject:model.REGION_NAME];
            }
        }
    }
    return _arrRegion;
}

@end
